using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CheckPoint : MonoBehaviour
{
    private Animator anim; // 动画控制器
    public string checkpointId; // 检查点ID
    public bool activated; // 是否激活

    private void Start()
    {
        anim = GetComponent<Animator>(); // 获取动画控制器组件
    }

    [ContextMenu("生成检查点ID")]
    private void GenerateId()
    {
        checkpointId = System.Guid.NewGuid().ToString(); // 生成新的唯一ID
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(activated)return;
        if (other.GetComponent<Player>() != null) // 检查碰撞的对象是否是玩家
        {
            ActivateCheckpoint(); // 激活检查点
        }
    }

    public void ActivateCheckpoint()
    {
        AudioManager.instance.PlaySFX(5, transform);
        activated = true; // 设置为激活状态
        anim.SetBool("active", true); // 播放激活动画
    }
}